package summer.presum;

public class Solution303 {
}

class NumArray {
    int[] sum;

    public NumArray(int[] nums) {
        sum = new int[nums.length];
        int preSum = 0;
        for (int i = 0; i < nums.length; i++) {
            sum[i] = preSum + nums[i];
            preSum = sum[i];
        }
    }

    public int sumRange(int left, int right) {
        if (left == 0) return sum[right];
        else return sum[right] - sum[left - 1];
    }
}